package com.peach.service.UserManage;

import com.peach.domain.UserManage.CurrentUser;
import com.peach.domain.UserManage.User;
import com.peach.service.UserManage.UserApplication;
import com.peach.utils.SqlConfig;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("UserApplication")
public class UserApplicationImpl implements UserApplication {

    private static SqlSessionTemplate sqlSessionTemplate = SqlConfig.sessionTemplateConfigure();

    public List<User> login(User user){

        return sqlSessionTemplate.selectList("UserMapper.selectUserWithId",user);

    }

    public int register(User user){
        return sqlSessionTemplate.insert("UserMapper.registerUserWithIdAndPasswordAndName",user);
    }

    public int modifyPassword(Map m){
        return sqlSessionTemplate.insert("UserMapper.modifyPassword",m);
    }

    public User selectUser(){
        return sqlSessionTemplate.selectOne("UserMapper.selectUser");
    }

    public CurrentUser selectCurrentUser(){
        return sqlSessionTemplate.selectOne("UserMapper.selectCurrentUser");
    }

    public int insertCurrentUser(Map<String,String> m){
        return sqlSessionTemplate.insert("UserMapper.insertCurrentUser",m);
    }

    public int deleteCurrentUser(){
        return sqlSessionTemplate.insert("UserMapper.deleteCurrentUser");
    }

}
